package com.ly.web.controller.erp;

import com.ly.common.annotation.Log;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.common.utils.StringUtils;
import com.ly.heart.domain.ContractAdminEntity;
import com.ly.heart.service.IContractAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 行政合同 前端控制器
 * </p>
 * @author WuZH
 * @since 2024-08-25
 */
@Api (value = "ContractAdmin", tags = "行政合同")
@RestController
@RequestMapping ("/heart/ContractAdmin")
public class ContractAdminController {

    @Resource
    private IContractAdminService iContractAdminService;

    @PreAuthorize ( "@ss.hasPermi('heart:ContractAdmin:list')" )
    @GetMapping ("/list")
    @ApiOperation ("行政合同列表")
    @Log (title = "行政合同列表")
    public AjaxResult list (ContractAdminEntity contractAdminEntity) {
        AjaxResult ajaxResult = iContractAdminService.queryList ( contractAdminEntity );
        return ajaxResult;
    }

    @PreAuthorize ( "@ss.hasPermi('heart:ContractProcure:query')" )
    @GetMapping ( value = "/{id}" )
    @ApiOperation ( "获取采购合同;1:采购;2:行政;详细信息" )
    public AjaxResult getInfo ( @PathVariable ( "id" ) String id ) {
        return AjaxResult.success ( iContractAdminService.querySingle ( id ) );
    }

    /**
     * 暂存;
     */
    @PreAuthorize ( "@ss.hasPermi('heart:ContractAdmin:add')" )
    @Log (title = "行政合同暂存;", businessType = BusinessType.INSERT)
    @PostMapping ("draft")
    @ApiOperation ("行政合同暂存;")
    public AjaxResult draft (@RequestBody ContractAdminEntity contractAdminEntity) {
        if ( StringUtils.isNotBlank ( contractAdminEntity.getId () ) ) {
            return iContractAdminService.updateSingle ( contractAdminEntity );
        }
        return iContractAdminService.draft ( contractAdminEntity );
    }

    /**
     * 新增采购合同;1:采购;2:行政;
     */
    @PreAuthorize ( "@ss.hasPermi('heart:ContractAdmin:add')" )
    @Log (title = "行政合同提交;", businessType = BusinessType.INSERT)
    @PostMapping ("submit")
    @ApiOperation ("行政合同提交;")
    public AjaxResult submit (@RequestBody ContractAdminEntity contractAdminEntity) {
        return iContractAdminService.submit ( contractAdminEntity );
    }

    /**
     * 修改采购合同;1:采购;2:行政;
     */
    @PreAuthorize ( "@ss.hasPermi('heart:ContractProcure:edit')" )
    @Log (title = "行政合同;", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation ("修改行政合同;")
    public AjaxResult edit (@RequestBody ContractAdminEntity contractAdminEntity) {
        return iContractAdminService.updateSingle ( contractAdminEntity );
    }

    /**
     * 删除采购合同;1:采购;2:行政;
     */
    @PreAuthorize ( "@ss.hasPermi('heart:ContractProcure:remove')" )
    @Log (title = "采购合同;1:采购;2:行政;", businessType = BusinessType.DELETE)
    @DeleteMapping ("/{ids}")
    @ApiOperation ("删除行政合同")
    public AjaxResult remove (@PathVariable String[] ids) {
        return iContractAdminService.deleteByIds ( ids );
    }


}
